/**
 * "Visual Paradigm: DO NOT MODIFY THIS FILE!"
 * 
 * This is an automatic generated file. It will be regenerated every time 
 * you generate persistence class.
 * 
 * Modifying its content may cause the program not work, or your work may lost.
 */

/**
 * Licensee: Hochschule Heilbronn
 * License Type: Academic
 */
package de.hhn.pmt.tour.u6;

import org.orm.*;
import org.hibernate.Query;
import org.hibernate.LockMode;
import java.util.List;

public class CoordinatesDAO {
	public static Coordinates loadCoordinatesByORMID(int ID)
			throws PersistentException {
		try {
			PersistentSession session = de.hhn.pmt.tour.u6.LNdMPersistentManager
					.instance().getSession();
			return loadCoordinatesByORMID(session, ID);
		} catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}

	public static Coordinates getCoordinatesByORMID(int ID)
			throws PersistentException {
		try {
			PersistentSession session = de.hhn.pmt.tour.u6.LNdMPersistentManager
					.instance().getSession();
			return getCoordinatesByORMID(session, ID);
		} catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}

	public static Coordinates loadCoordinatesByORMID(int ID,
			org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = de.hhn.pmt.tour.u6.LNdMPersistentManager
					.instance().getSession();
			return loadCoordinatesByORMID(session, ID, lockMode);
		} catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}

	public static Coordinates getCoordinatesByORMID(int ID,
			org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = de.hhn.pmt.tour.u6.LNdMPersistentManager
					.instance().getSession();
			return getCoordinatesByORMID(session, ID, lockMode);
		} catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}

	public static Coordinates loadCoordinatesByORMID(PersistentSession session,
			int ID) throws PersistentException {
		try {
			return (Coordinates) session.load(
					de.hhn.pmt.tour.u6.Coordinates.class, new Integer(ID));
		} catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}

	public static Coordinates getCoordinatesByORMID(PersistentSession session,
			int ID) throws PersistentException {
		try {
			return (Coordinates) session.get(
					de.hhn.pmt.tour.u6.Coordinates.class, new Integer(ID));
		} catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}

	public static Coordinates loadCoordinatesByORMID(PersistentSession session,
			int ID, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			return (Coordinates) session.load(
					de.hhn.pmt.tour.u6.Coordinates.class, new Integer(ID),
					lockMode);
		} catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}

	public static Coordinates getCoordinatesByORMID(PersistentSession session,
			int ID, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			return (Coordinates) session.get(
					de.hhn.pmt.tour.u6.Coordinates.class, new Integer(ID),
					lockMode);
		} catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}

	public static List queryCoordinates(String condition, String orderBy)
			throws PersistentException {
		try {
			PersistentSession session = de.hhn.pmt.tour.u6.LNdMPersistentManager
					.instance().getSession();
			return queryCoordinates(session, condition, orderBy);
		} catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}

	public static List queryCoordinates(String condition, String orderBy,
			org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = de.hhn.pmt.tour.u6.LNdMPersistentManager
					.instance().getSession();
			return queryCoordinates(session, condition, orderBy, lockMode);
		} catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}

	public static Coordinates[] listCoordinatesByQuery(String condition,
			String orderBy) throws PersistentException {
		try {
			PersistentSession session = de.hhn.pmt.tour.u6.LNdMPersistentManager
					.instance().getSession();
			return listCoordinatesByQuery(session, condition, orderBy);
		} catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}

	public static Coordinates[] listCoordinatesByQuery(String condition,
			String orderBy, org.hibernate.LockMode lockMode)
			throws PersistentException {
		try {
			PersistentSession session = de.hhn.pmt.tour.u6.LNdMPersistentManager
					.instance().getSession();
			return listCoordinatesByQuery(session, condition, orderBy, lockMode);
		} catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}

	public static List queryCoordinates(PersistentSession session,
			String condition, String orderBy) throws PersistentException {
		StringBuffer sb = new StringBuffer(
				"From de.hhn.pmt.tour.u6.Coordinates as Coordinates");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			return query.list();
		} catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}

	public static List queryCoordinates(PersistentSession session,
			String condition, String orderBy, org.hibernate.LockMode lockMode)
			throws PersistentException {
		StringBuffer sb = new StringBuffer(
				"From de.hhn.pmt.tour.u6.Coordinates as Coordinates");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			query.setLockMode("Coordinates", lockMode);
			return query.list();
		} catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}

	public static Coordinates[] listCoordinatesByQuery(
			PersistentSession session, String condition, String orderBy)
			throws PersistentException {
		try {
			List list = queryCoordinates(session, condition, orderBy);
			return (Coordinates[]) list.toArray(new Coordinates[list.size()]);
		} catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}

	public static Coordinates[] listCoordinatesByQuery(
			PersistentSession session, String condition, String orderBy,
			org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			List list = queryCoordinates(session, condition, orderBy, lockMode);
			return (Coordinates[]) list.toArray(new Coordinates[list.size()]);
		} catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}

	public static Coordinates loadCoordinatesByQuery(String condition,
			String orderBy) throws PersistentException {
		try {
			PersistentSession session = de.hhn.pmt.tour.u6.LNdMPersistentManager
					.instance().getSession();
			return loadCoordinatesByQuery(session, condition, orderBy);
		} catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}

	public static Coordinates loadCoordinatesByQuery(String condition,
			String orderBy, org.hibernate.LockMode lockMode)
			throws PersistentException {
		try {
			PersistentSession session = de.hhn.pmt.tour.u6.LNdMPersistentManager
					.instance().getSession();
			return loadCoordinatesByQuery(session, condition, orderBy, lockMode);
		} catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}

	public static Coordinates loadCoordinatesByQuery(PersistentSession session,
			String condition, String orderBy) throws PersistentException {
		Coordinates[] coordinateses = listCoordinatesByQuery(session,
				condition, orderBy);
		if (coordinateses != null && coordinateses.length > 0)
			return coordinateses[0];
		else
			return null;
	}

	public static Coordinates loadCoordinatesByQuery(PersistentSession session,
			String condition, String orderBy, org.hibernate.LockMode lockMode)
			throws PersistentException {
		Coordinates[] coordinateses = listCoordinatesByQuery(session,
				condition, orderBy, lockMode);
		if (coordinateses != null && coordinateses.length > 0)
			return coordinateses[0];
		else
			return null;
	}

	public static java.util.Iterator iterateCoordinatesByQuery(
			String condition, String orderBy) throws PersistentException {
		try {
			PersistentSession session = de.hhn.pmt.tour.u6.LNdMPersistentManager
					.instance().getSession();
			return iterateCoordinatesByQuery(session, condition, orderBy);
		} catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}

	public static java.util.Iterator iterateCoordinatesByQuery(
			String condition, String orderBy, org.hibernate.LockMode lockMode)
			throws PersistentException {
		try {
			PersistentSession session = de.hhn.pmt.tour.u6.LNdMPersistentManager
					.instance().getSession();
			return iterateCoordinatesByQuery(session, condition, orderBy,
					lockMode);
		} catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}

	public static java.util.Iterator iterateCoordinatesByQuery(
			PersistentSession session, String condition, String orderBy)
			throws PersistentException {
		StringBuffer sb = new StringBuffer(
				"From de.hhn.pmt.tour.u6.Coordinates as Coordinates");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			return query.iterate();
		} catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}

	public static java.util.Iterator iterateCoordinatesByQuery(
			PersistentSession session, String condition, String orderBy,
			org.hibernate.LockMode lockMode) throws PersistentException {
		StringBuffer sb = new StringBuffer(
				"From de.hhn.pmt.tour.u6.Coordinates as Coordinates");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			query.setLockMode("Coordinates", lockMode);
			return query.iterate();
		} catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}

	public static Coordinates createCoordinates() {
		return new de.hhn.pmt.tour.u6.Coordinates();
	}

	public static boolean save(de.hhn.pmt.tour.u6.Coordinates coordinates)
			throws PersistentException {
		try {
			de.hhn.pmt.tour.u6.LNdMPersistentManager.instance().saveObject(
					coordinates);
			return true;
		} catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}

	public static boolean delete(de.hhn.pmt.tour.u6.Coordinates coordinates)
			throws PersistentException {
		try {
			de.hhn.pmt.tour.u6.LNdMPersistentManager.instance().deleteObject(
					coordinates);
			return true;
		} catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}

	public static boolean deleteAndDissociate(
			de.hhn.pmt.tour.u6.Coordinates coordinates)
			throws PersistentException {
		try {
			if (coordinates.getStation() != null) {
				coordinates.getStation().setCoordinates(null);
			}

			if (coordinates.getPoi() != null) {
				coordinates.getPoi().setCoordinates(null);
			}

			return delete(coordinates);
		} catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}

	public static boolean deleteAndDissociate(
			de.hhn.pmt.tour.u6.Coordinates coordinates,
			org.orm.PersistentSession session) throws PersistentException {
		try {
			if (coordinates.getStation() != null) {
				coordinates.getStation().setCoordinates(null);
			}

			if (coordinates.getPoi() != null) {
				coordinates.getPoi().setCoordinates(null);
			}

			try {
				session.delete(coordinates);
				return true;
			} catch (Exception e) {
				return false;
			}
		} catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}

	public static boolean refresh(de.hhn.pmt.tour.u6.Coordinates coordinates)
			throws PersistentException {
		try {
			de.hhn.pmt.tour.u6.LNdMPersistentManager.instance().getSession()
					.refresh(coordinates);
			return true;
		} catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}

	public static boolean evict(de.hhn.pmt.tour.u6.Coordinates coordinates)
			throws PersistentException {
		try {
			de.hhn.pmt.tour.u6.LNdMPersistentManager.instance().getSession()
					.evict(coordinates);
			return true;
		} catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}

}
